import datetime
from sqlalchemy import UniqueConstraint

from toutiao.model.j import db


class User(db.Model):
    __tablename__="User"
    id=db.Column(db.BigInteger,primary_key=True,autoincrement=True)
    phone=db.Column(db.String(225),default='')
    account=db.Column(db.String(225),default='')
    avatar=db.Column(db.String(225),default='')
    sex=db.Column(db.Integer,default='')
    birth_data=db.Column(db.DateTime,default=datetime.datetime.now)
    profile_photo=db.Column(db.String(225))
    following_count=db.Column(db.SmallInteger,default=0)
    fans_count=db.Column(db.Integer,default=0)
    password=db.Column(db.String(225),default="",)
    ctime=db.Column(db.DateTime,default=datetime.datetime.now)
    mtime=db.Column(db.DateTime,default=datetime.datetime.now,onupdate=datetime.datetime.now())


class relation_jj(db.Model):
    __tablename__ = "relation_jj"

    __table_arge=(
        UniqueConstraint('target_user_id','user_id','relation',name='relation_unique')
    )
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    target_user_id=db.Column(db.Integer,default='')
    user_id = db.Column(db.Integer,default='')
    relation=db.Column(db.String(225),default='关注')
    is_deleted=db.Column(db.Integer,default=1)
    ctime = db.Column(db.DateTime, default=datetime.datetime.now)
    mtime = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now())


class Channel(db.Model):
    __tablename__="channel"
    id=db.Column(db.BigInteger,primary_key=True,autoincrement=True)
    name=db.Column(db.String(225),unique=True,nullable=False)
    type = db.Column(db.SmallInteger,default=1)
    ctime=db.Column(db.DateTime,default=datetime.datetime.now)
    mtime=db.Column(db.DateTime,default=datetime.datetime.now,onupdate=datetime.datetime.now())


class UserChannel(db.Model):
    __tablename__="user_channel"
    id=db.Column(db.BigInteger,primary_key=True,autoincrement=True)
    user_id=db.Column(db.BigInteger,nullable=False)
    is_deleted = db.Column(db.SmallInteger,default=1)
    channel_id=db.Column(db.BigInteger,nullable=False)
    ctime=db.Column(db.DateTime,default=datetime.datetime.now)
    mtime=db.Column(db.DateTime,default=datetime.datetime.now,onupdate=datetime.datetime.now())

#
class ArticContent(db.Model):
    __tablename__ = "articContent"
    id=db.Column(db.BigInteger,primary_key=True,comment='主键',autoincrement=True)
    artist_id=db.Column(db.BigInteger)
    content=db.Column(db.Text)
    ctime = db.Column(db.DateTime, default=datetime.datetime.now)
    mtime = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now())

class Artic_User(db.Model):
    __tablename__ = "artic_user"
    id=db.Column(db.BigInteger,primary_key=True,comment='主键',autoincrement=True)
    user_id=db.Column(db.BigInteger,comment='用户id')
    artice_id=db.Column(db.BigInteger,comment='文章')
    ctime = db.Column(db.DateTime, default=datetime.datetime.now)
    mtime = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now())

class Artice(db.Model):
    __tablename__ = "Artice"
    id=db.Column(db.BigInteger,primary_key=True,doc='主键',autoincrement=True)
    user_id=db.Column(db.BigInteger,comment='用户id')
    channel_id=db.Column(db.SmallInteger,comment='频道_id')
    title=db.Column(db.String(250),comment='标题')
    img=db.Column(db.String(64),default='',comment='图片路径')
    comment_count=db.Column(db.Integer,default=0,comment='评论数量')
    allow_comment=db.Column(db.Boolean,default=True,comment='是否允许评论 True允许评论，False不允许评论')
    status=db.Column(db.Integer,default=0,comment='文章状态 0-草稿，1-待审核，2-发布成功')
    is_visible=db.Column(db.SmallInteger,comment='是否可见 ，0是可见，1是不可见')
    likes_count=db.Column(db.Integer,comment='点赞数',default=0,)
    collection_count=db.Column(db.Integer,default=0,comment='被收藏数')
    is_deleted = db.Column(db.SmallInteger, comment='是否删除 ，0是软删除1，是未删除')
    ctime = db.Column(db.DateTime, default=datetime.datetime.now)
    mtime = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now())